// 寻找两个正序数组中的中位数

let nums1 = [1,3], nums2 = [2]

var findMedianSortedArrays = function(nums1, nums2) {
    let m = nums1.length, n = nums2.length
    let len = m + n
    let i = 0, j = 0
    let newArr = []
    while (i < m && j < n) {
        if(nums1[i] < nums2[j]) {
            newArr.push(nums1[i])
            i++
        }
        else {
            newArr.push(nums2[j])
            j++
        }
    }

  newArr =  newArr.concat(i < m ? nums1.slice(i) : nums2.slice(j))

    if(len % 2 === 0) {
        return newArr[len / 2 - 1] + newArr[len / 2]
    } else {
        return newArr[Math.floor(len / 2)]
    }
}